/**
 * 
 */
package edu.umd.clip.lm.model;

import java.io.*;

import edu.umd.clip.lm.util.BinaryPrefix;
import com.sleepycat.bind.tuple.*;
/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public abstract class AbstractCompactProbTree implements Cloneable, Externalizable {
	protected static final byte COMPACT_TREE_TYPE = 0;
	protected static final byte SINGLE_LEAF_TYPE = 1;
	
	// cut branches
	public abstract AbstractCompactProbTree prune(final double threshold);

	public abstract AbstractCompactProbTree compact();

	//public abstract double getProbability(BinaryPrefix path);
	public abstract double getProbability(int packedHiddenFactors);
	//public abstract void setProbability(BinaryPrefix path, double prob);
	public abstract void setProbability(int packedHiddenFactors, double prob);
	//public abstract void addProbability(BinaryPrefix path, double prob);
	public abstract void addProbability(int packedHiddenFactors, double prob);
	
	public abstract boolean checkTree();

	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
	public abstract Object clone();

	public abstract void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;

	public void writeExternal(ObjectOutput out) throws IOException {
		out.writeByte(getType());
	}

	public abstract void readTuple(TupleInput in) throws IndexOutOfBoundsException;

	public void writeTuple(TupleOutput out) {
		out.writeByte(getType());
	}
	/*
	public abstract boolean isCompactProbTree();
	
	public abstract DecoderCompactProbTree getCompactProbTree();
	
	public DecoderCompactProbTree getCompactProbTreeReadOnly() {
		return getCompactProbTree();
	}
	*/
	public abstract void scale(double scale);
	
	public abstract double getTotalProb();
	
	public abstract byte getType();
	
}